package com.zjy.software.day7;

public class InterfaceTest {
    public static void main(String[] args)
    {
        //演示多态的生成,接口声明,子类实现
       Run car=new Car();
       Run dog=new Dog();
       Run Teacher=new Teacher();
       Run pc=new AIPC();

       pc=new Dog();

       //演示多态的调用,以及扩展性
        executeRun(car);
        executeRun(dog);
        executeRun(Teacher);
        executeRun(pc);

        //演示子类自动隐式的转化为父类的过程
        Car newCar=new Car();
        Run newTmpCar=newCar;

        //演示向下转型,把父类转化为子类
        Run newRun=new Dog();
        Dog tmpDog=(Dog)newRun;
        executeRun(tmpDog);

        //演示不成功的向下转型
        Run tmpCar=new Car();
        if (tmpCar  instanceof Dog) {
            Dog paramDog=(Dog)tmpCar;
            executeRun(paramDog);
        }else {
            System.out.println("不是小狗类型,不能向下转型");
        }


    }

    public static void executeRun(Run run){
        run.execute();
    }
}
